import { addBuildingAPI, deleteBuilding, fetchBuildingListAPI, updateBuildingAPI } from '@/api/park/building'

const actions = {
  /* 用于发送请求获取楼宇列表的action */
  async fetchBuildingList(context, pageParams) {
    const { data } = await fetchBuildingListAPI(pageParams)
    context.commit('updateBuildingList', data)
  },

  /* 用于发送请求添加楼宇的action */
  async addBuilding(context, formData) {
    const { msg } = await addBuildingAPI(formData)
    return msg
  },

  /* 用于发送请求编辑楼宇的action */
  async updateBuilding(context, formData) {
    const { msg } = await updateBuildingAPI(formData)
    return msg
  },

  /* 用于发送请求删除楼宇的action */
  async deleteBuilding(context, id) {
    const { msg } = await deleteBuilding(id)
    return msg
  }
}
const mutations = {
  /* 更新楼宇列表的mutation */
  updateBuildingList(state, buildingListInfo) {
    state.buildingListInfo = buildingListInfo
  }
}
const state = () => {
  return {
    buildingListInfo: {}
  }
}
const getters = {
  buildingList(state) {
    return state.buildingListInfo.rows
  },
  total(state) {
    return state.buildingListInfo.total
  }
}
export default {
  actions,
  mutations,
  state,
  getters,
  namespaced: true
}
